#ifndef __MV_PUB_H__
#define __MV_PUB_H__

#ifndef __cplusplus
#  error core.hpp header must be compiled as C++
#endif

#include <opencv2/opencv.hpp>

using namespace cv;

// 二值化方法
enum {
	MV_THRESHOLD_ADAPTIVE = 0, MV_THRESHOLD_FIX = 1
};
enum {
	MV_MIRROR_HOR = 0, MV_MIRROR_VER = 1
};

class MvPub {

public:
	// 求放大后的矩形座标(p00,p01,p10,p11)
	void calRectangle(InputArray pts, float cal, float calY, OutputArray outPts);

	// 计算２点距离
	float calDistance(Point2f p0, Point2f p1);
	void calDistances(InputArray p, OutputArray o);

	// 计算２点与水平线的夹角（０。。。３６０）
	float calAngle(Point2f p0, Point2f p1);
	void calAngles(InputArray p, OutputArray o);

	// 计算座示点旋转
	void rotatePoints(InputArray inPts, Point2f center, float angle, OutputArray outPts);
	// 移动座标集
	void movePoints(InputArray inPts, Point2f offset, OutputArray outPts);

	// 绘制交叉线十字线
	void drawXLine(Mat& src, Point2f &pt, Scalar sclr, int width, int len);

	// 生成十字模板
	void makeTemp7x7Strong(OutputArray temp);
	void makeTemp7x7StrongInv(OutputArray temp);

	Mat makeTempX(int x, int y); // 十字数1，背景为0
	Mat makeInvTempX(int x, int y);

	// 图像镜相
	void mirrorTrans(const Mat &src, Mat &dst, int mirror);

	// 查找十字交叉线中心座标
	int findCrossPoints(Mat &src, OutputArray pts);

	// 通过圆心，半径，源座标求投影座标
	// x0,y0:圆心座标；u,v:投影座标
	float getCircleMapSrcX(int u, int v, float x0, float y0, float r);
	float getCircleMapSrcY(int u, int v, float x0, float y0, float r);
	Point2f getCircleMapSrcPoint(int u, int v, float x0, float y0, float r);
	void getCircleMapSrcPic(Mat &dst, Mat &src, int r);

	// 二值化
	int threshholdEx(Mat &src, int thresholdMode, int thresholdValue, int blocksize, int offset);
	// 查找棋盘
	int findChessBoard(Mat &src, OutputArray vertexs, int thresholdValue = 127, int blocksize = 95, int offset = 5);
	int findChessBoardBlock(Mat &src, OutputArray vertexs, int thresholdMode, int thresholdValue, int blocksize,
			int offset);

	// 透视变换
	// srcPoints：输入的4个点，dstPoints：变换后的4个目标点，输出变换后的图像
	int perspectiveInvTransform(Mat &src, InputArray srcCorner, InputArray dstCorner, int interpolation,
			OutputArray img);
	// 输出变换前的座标
	int perspectiveInvTransform(Size imgSize, InputArray srcCorner, InputArray dstCorner, OutputArray OutPts);
	int perspectivePosTransform(InputArray inPts, InputArray srcCorner, InputArray dstCorner, OutputArray OutPts);

	// 梯形（方形） src：目标图像；horScalUp，horScalDown，verScal：变换后上下高占图像比例；posScalCU：变换后下中心位座标位置比例；
	int makePerspectiveCorners(float horScalUp, float horScalDown, float verScal, Point2f posCenterDown,
			OutputArray corner);

	//图像混合并处理透明
	void blending(Mat &src, Mat &dst, int alpha, int trans);
};

#endif
